//
//  ViewManager.m
//  projectBase
//
//  Created by zhuangzhh on 14-11-14.
//  Copyright (c) 2014年 zhuangzhh. All rights reserved.
//

#import "ViewManager.h"
#import "YMTTabBarController.h"
#import "PersonController.h"
#import "SizeHeader.h"
#import "PubFunction.h"
#import "LoginController.h"
#import "StudentLoginController.h"
#import "HomeViewController.h"
#import "classViewController.h"
#import "myViewController.h"


@implementation ViewManager

static ViewManager* mInstance;

@synthesize NavigationController = _navigationController;


+ (ViewManager*)shareInstance
{
    if (nil == mInstance)
    {
        mInstance = [[ViewManager alloc] init];
    }
    
    return mInstance;
}
//创建首页底部导航
-(YMTTabBarController *)createYMTTabBarController
{
    HomeViewController* homeVC = [[HomeViewController alloc]init];
    classViewController* konwledgeVC = [[classViewController alloc]init];
    myViewController* fenLeiVc = [[myViewController alloc]init];
    
    YMTTabBarController *_tabBarViewController = [[YMTTabBarController alloc] initYMTTabBarVC:[NSArray arrayWithObjects:homeVC, konwledgeVC,fenLeiVc, nil]];
    NSArray *itemImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"home_before"],[UIImage imageNamed:@"knowledge_before"],[UIImage imageNamed:@"personal_before"],nil];
    NSArray *highImage = [NSArray arrayWithObjects:[UIImage imageNamed:@"home_after"],[UIImage imageNamed:@"knowledge_after"],[UIImage imageNamed:@"personal_after"],nil];
    [_tabBarViewController setYMTTabBarItemImage:itemImages highImage:highImage];
    [_tabBarViewController setYMTTabBarItemTitle:[NSArray arrayWithObjects:@"首页",@"班级",@"我的", nil]];
    _tabBarViewController.tabBar.unselectedItemTintColor = UIColorRGB(138);
    _tabBarViewController.tabBar.selectedImageTintColor = CJYColor(0, 160, 244);
    _tabBarViewController.delegate = self;
    return _tabBarViewController;
    
}


-(id)init
{
    self = [super init];
    if(self != nil)
    {
        if([[AppData getpersonshopmid] intValue] == 0||[[AppData getpersonshopmid] intValue] == 1)
        {
            _navigationController = [[UINavigationController alloc] initWithRootViewController:[self createYMTTabBarController]];
        }
        _navigationController.navigationBar.hidden = YES;
        _navigationController.interactivePopGestureRecognizer.enabled = YES;
        [[NSNotificationCenter defaultCenter] addObserver: self
                                                 selector: @selector(skinAction:)
                                                     name: Notify_ChangeSkin
                                                   object: nil];
    }
    
    return self;
}

-(void)skinAction:(id)sender
{
//    NSString *skin = [[NSUserDefaults standardUserDefaults] objectForKey:@"skin"];
//    if([skin isEqualToString:@"1"])
//    {
        YMTTabBarController *tabbarvc = [[ViewManager shareInstance].NavigationController.viewControllers objectAtIndex:0];
        [tabbarvc setYMTTabBarItemImage:[NSArray arrayWithObjects:[PubFunction GetSkinImage:@"tab1"],[PubFunction GetSkinImage:@"tab2"],[PubFunction GetSkinImage:@"tab3"],[PubFunction GetSkinImage:@"tab4"],[PubFunction GetSkinImage:@"suggest_icon"],nil] highImage:[NSArray arrayWithObjects:[PubFunction GetImage:@"tab1s"],[PubFunction GetSkinImage:@"tab2s"],[PubFunction GetSkinImage:@"tab3s"],[PubFunction GetSkinImage:@"tab4s"],[PubFunction GetSkinImage:@"suggest_icon"],nil]];
//        [[NSNotificationCenter defaultCenter] postNotificationName:Notify_TabBarOfColor
//                                                            object:[NSNumber numberWithInt:2]];
//    }
//    else
//    {
//        YMTTabBarController *tabbarvc = [[ViewManager shareInstance].NavigationController.viewControllers objectAtIndex:0];
//        [tabbarvc setYMTTabBarItemImage:[NSArray arrayWithObjects:[PubFunction GetSkinImage:@"tab1"],[PubFunction GetSkinImage:@"tab2"],[PubFunction GetSkinImage:@"tab3"],[PubFunction GetSkinImage:@"tab4"],[PubFunction GetSkinImage:@"suggest_icon"],nil] highImage:[NSArray arrayWithObjects:[PubFunction GetImage:@"tab1s"],[PubFunction GetImage:@"tab2s"],[PubFunction GetImage:@"tab3s"],[PubFunction GetImage:@"tab4s"],[PubFunction GetImage:@"suggest_icon"],nil]];
//        [[NSNotificationCenter defaultCenter] postNotificationName:Notify_TabBarOfColor
//                                                            object:[NSNumber numberWithInt:2]];
//    }


}

//- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController NS_AVAILABLE_IOS(3_0)
//{
//    if(([AppData shareInstance].indexOfSelectedTabItem == PersonTag|| [AppData shareInstance].indexOfSelectedTabItem == CLASSTAG) && [AppData shareInstance].isLogin == NO)
//    {
//        return NO;
//    }
//    return YES;
//}

-(void)toMainPlat
{
   [_navigationController pushViewController:[self createYMTTabBarController] animated:YES];
}


@end
